<?php
class ProductCompo extends AppModel{
    public $useTable  = 'product_compo';

    
    function add($data = array())
    {
        return($this->save($data));
    }

    function del($product_id = null)
    {
       //return $this->deleteAll(array('product_id' => $product_id));
       $sql = "DELETE FROM product_compo WHERE product_id = '$product_id'";
   	    return $this->query($sql);
    }
    
    function get_compo_by_product_id($product_id = null)
    {
        $sql = array(
			"conditions"=> array(
							"product_id ="=> $product_id,
						),
			);
        $data = $this->find("all",$sql);
        $result = array();
        foreach($data as $value)
        {
            $lang_code = $value['ProductCompo']['lang_code'];
            $compo_id = $value['ProductCompo']['compo_id'];
            $content = $value['ProductCompo']['content'];
            $result[$lang_code][$compo_id] = $content;
        }
        
        return $result;
    }
}
